function defineProperty_demo(opt) {
	if (opt < 0) return;
	var obj = {
		abc: -1
	};
	Object.defineProperty(obj, "abc", {
		//可以监听通过 Object.defineProperty() 定义的属性。
		set: function(value) {
			if (obj._weilai == null) {
				obj._weilai = {};
			}
			obj._weilai.abc = value;
			console.log(' set...' + value);

		},
		get: function() {
			if (obj._weilai == null)
				return obj.abc;
			console.log(' get...' + obj._weilai.abc);
			return obj._weilai.abc;
		}
	});
	obj.abc = 100;
	setInterval(function() {//赋值和显示都被拦截了
		obj.abc += 2;
		document.getElementById("input1").value = "obj.abc=" + obj.abc;
	}, 1000);
}
const js9 = {//18161896101
	clone: function(obj) {
		var buf;
		if (obj instanceof Array) {
			buf = [];
			var i = obj.length;
			while (--i >= 0) {
				buf[i] = js9.clone(obj[i]);
			}
			return buf;
		} else if (obj instanceof Function) {
			//?
		} else if (obj instanceof Object) {
			buf = {};
			for (var k in obj) {
				buf[k] = js9.clone(obj[k]);
			}
			return buf;
		}
		return obj;
	},
	listenObj_asAttr: function(obj) {//监听对象中的属性变化,未起作用
		let root = {
			obj: obj,
			weilai: obj
		};
		Object.defineProperty(root, "obj", {
			//可以监听通过 Object.defineProperty() 定义的属性。
			set: function(value) {
				root.weilai.obj = value;
				console.log("listenObj.set " + attName + "...=" + value);

			},
			get: function() {
				let value = root.weilai.obj;
				console.log("listenObj.get " + attName + "...=" + value);
				return value;
			}
		});
	},
	listenObj: function(obj, attNames) {//监听对象中的属性变化
		var cpy = js9.clone(obj);
		obj._weilai = cpy;//
		const arr = Object.keys(obj);
		for (var ind in arr) {
			const attName = arr[ind];//must be const, else listen fail.
			if (attName == '_weilai')
				continue;
			const attValue = obj[attName];
			if (attValue instanceof Object) {
				js9.listenObj(attValue, attNames);//递归深入监听
				return;
			}
			if (attNames != null) {
				if (attNames.length > 0 && attNames.indexOf(attName) == -1)
					continue;
			}

			console.log("defineProperty:" + attName);
			Object.defineProperty(obj, attName, {
				//可以监听通过 Object.defineProperty() 定义的属性。
				set: function(value) {
					obj._weilai[attName] = value;
					console.log("listenObj.set " + attName + " =" + value);

				},
				get: function() {
					let value = obj._weilai[attName];
					console.log("listenObj.get " + attName + " " + value);
					return value;
				}
			});
			//return;
		}
	}
}
